/**
 * 
 */
package org.intelligentsia.artifacts.repository.metadata.adapter;

import org.json.JSONException;
import org.json.JSONObject;

import org.intelligentsia.artifacts.repository.metadata.Plugin;

/**
 * Plugin Adapter class.
 * 
 * @author <a href="mailto:jguibert@intelligents-ia.com" >Jerome Guibert</a>
 */
public class PluginAdapter {

	public static Plugin read(JSONObject jsonObject) throws JSONException {
		Plugin plugin = null;
		if (jsonObject != null) {
			plugin = new Plugin();
			plugin.setName(jsonObject.optString("name"));
			plugin.setPrefix(jsonObject.optString("prefix"));
			plugin.setArtifactId(jsonObject.optString("artifactId"));
		}
		return plugin;
	}

	public static JSONObject write(Plugin plugin) throws JSONException {
		JSONObject jsonObject = null;
		if (plugin != null) {
			jsonObject = new JSONObject();
			jsonObject.putOpt("name", plugin.getName());
			jsonObject.putOpt("prefix", plugin.getPrefix());
			jsonObject.putOpt("artifactId", plugin.getArtifactId());
		}
		return jsonObject;
	}
}
